package edu.isquen.core.base.service;

import java.util.Collection;
import java.util.UUID;

import edu.isquen.core.base.dao.DataPackage;
import edu.isquen.core.base.dao.IBaseDAO;
import edu.isquen.core.base.model.ValueObject;
import edu.isquen.util.CommUtil;
import edu.isquen.util.factory.DaoFactory;

/****************************************************
* 文件名：BaseServiceImpl.java
* 文件描述：基类业务实现类
* 创建人： isquen, 2011 年6 月10 日
* 版本号：1.0
* 修改记录：
****************************************************/
public abstract class BaseServiceImpl implements BaseService{
	
	private static final long serialVersionUID = -4389699935531296316L;

	public IBaseDAO<?> getDao(String className) throws Exception{
		return DaoFactory.getDao(className);
	}

	public void doCreate(ValueObject vo) throws Exception {
		if(!CommUtil.validateString(vo.getId())){
			vo.setId(UUID.randomUUID().toString());
		}
		this.getDao().create(vo);
	}

	public void doCreate(ValueObject[] vos) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void doCreate(Collection<ValueObject> cols) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public int doGetTotalLines(String sql) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@SuppressWarnings("unchecked")
	public DataPackage<ValueObject> doQuery() throws Exception {
		return (DataPackage<ValueObject>) this.getDao().getDatas();
	}

	public void doRemove(String key) throws Exception {
		getDao().remove(key);
		
	}

	public void doRemove(String[] keys) throws Exception {
		if(keys!=null && keys.length>0){
			for (int i = 0; i < keys.length; i++) {
				getDao().remove(keys[i]);
			}
		}
		
	}

	public void doRemove(ValueObject vo) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void doUpdate(ValueObject vo) throws Exception {
		getDao().update(vo);
	}

	public void doUpdate(ValueObject[] vos) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void doUpdate(Collection<ValueObject> cols) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public ValueObject doView(String key) throws Exception {
		return this.getDao().find(key);
	}

	public DataPackage<ValueObject> doViewByName(String name) throws Exception {
		return null;
	}
	
	public abstract IBaseDAO<?> getDao() throws Exception;
}
